﻿using QRCodeEncoderLibrary;
using System;
using System.Drawing;
using System.Windows.Forms;


namespace PPTHelper
{
    public partial class Form3 : Form
    {
        const int timeout = 8000;        //超时关闭窗口
        public Form3(string url, string title = "")
        {
            InitializeComponent();
            StartPosition = FormStartPosition.Manual;
            Location = MousePosition;
            linkLabel1.Text = url.Trim();
            label1.Text = title.Trim();
            pictureBox1.Image = GetQrCode(linkLabel1.Text);
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            this.Text = PPTHelper.Title;
            this.FormBorderStyle = FormBorderStyle.None;  //无边框
            this.ShowInTaskbar = false; //任务栏
            this.Opacity = 0.9;   //透明
            this.TopMost = true;
            var timer = new Timer { Interval = timeout, Enabled = true };
            timer.Tick += Timer_Tick;
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            this.Close();
        }

        Bitmap GetQrCode(string text)
        {
            try
            {
                var qr = new QREncoder();
                qr.Encode(text);
                return qr.CreateQRCodeBitmap();
            }
            catch (Exception ex)
            {
                Log.Info("GetQrCode：" + ex.Message);
                return null;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Help.ShowHelp(this, linkLabel1.Text);
        }

        private void Form3_MouseDown(object sender, MouseEventArgs e)
        {
            Win32Api.Control_MouseDown(this.Handle);
        }
    }
}
